package com.college.dao;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class WorkBaseDao<T> extends HibernateDaoSupport {

	public List queryEntiy(final String hql, final Object... params) {
		return (List) getHibernateTemplate().execute(
				new HibernateCallback<List>() {
					@Override
					public List doInHibernate(Session session)
							throws HibernateException, SQLException {
						Query query = session.createQuery(hql);
						for (int i = 0; i < params.length; i++) {
							query.setParameter(i, params[i]);
						}
						return query.list();
					}
				});
	}

	public void save(Object object) {
		getHibernateTemplate().save(object);
	}
	public void update(String hql) {
		getHibernateTemplate().bulkUpdate(hql);
	}
}
